package com.harvest.scientific.ladder.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.core.content.ContextCompat
import com.harvest.scientific.ladder.R
import com.harvest.scientific.ladder.databinding.CommonActionBarBinding
import com.harvest.scientific.ladder.ext.visible
import com.harvest.scientific.ladder.util.VcUtil

/**
 * @author：zenglingwen
 * @date：2024-06-08 17:43
 * @desc：
 */
class BaseActionBar @JvmOverloads constructor(
    context: Context,
    attrSets: AttributeSet? = null,
    defStyleAttrs: Int = 0
) : FrameLayout(context, attrSets, defStyleAttrs) {

    private var _binding: CommonActionBarBinding

    init {
        val view = View.inflate(context, R.layout.common_action_bar, null)
        _binding = CommonActionBarBinding.bind(view)
        addView(view)
    }


    fun showDivider(isShow: Boolean) {
        _binding.divider.visible(isShow)
    }

    fun setVisible(isVisible: Boolean) {
        _binding.root.visible(isVisible)
    }

    fun setBlackMode(enable: Boolean) {
        if (enable) {
            _binding.backIv.setImageResource(R.mipmap.black_back_icon)
            _binding.customerIv.setImageResource(R.mipmap.black_customer_icon)
            _binding.barTitle.setTextColor(ContextCompat.getColor(context, R.color.color_333))
            showDivider(true)
        }
    }

    fun setTitle(title: String) {
        _binding.barTitle.text = title
    }

    fun isShowBack(isShowBack: Boolean) {
        _binding.backContainer.visible(isShowBack)
    }

    fun isShowBusinessServer(isShow: Boolean) {
        _binding.businessServer.visible(isShow)
    }

    fun setBackListener(backListener: OnClickListener) {
        _binding.backContainer.setOnClickListener {
            if (VcUtil.isFastDoubleClick(it)) {
                return@setOnClickListener
            }
            backListener.onClick(it)

        }
    }

    fun setCustomerListener(customerListener: OnClickListener) {
        _binding.businessServer.setOnClickListener {

            if (VcUtil.isFastDoubleClick(it)) {
                return@setOnClickListener
            }

            customerListener.onClick(it)
        }
    }
}